home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
ndr3.exe
/
VERIPX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-04
|
4KB
|
148 lines
/*
VERIPX.C shows how to obtain the IPX/SPX version number
without using Diagnostics.
Author: Tim Farley
Copyright 1993, Tim Farley, All Rights Reserved
*/
#include <stdlib.h> /* for NULL */
#include <dos.h> /* for "GETVECT" and FP_OFF() */
#ifdef __TURBOC__
#define ASM asm
#define GETVECT getvect
#else
/* assume Microsoft C if not Turbo/Borland C */
#define ASM _asm
#define GETVECT _dos_getvect
#endif
/*
Pointer to the IPX entry point
*/
static void (far * IPXentry)(void) = NULL;
/*
Pointer to the IPX signature string
*/
static void far * IPXsignature = NULL;
/*
DetectIPX detects if IPX is present and fills in
the two pointers above.
*/
static int DetectIPX( void )
{
unsigned long int2Fvector;
int returnCode;
/* if we've already been called, skip it */
if ( NULL != IPXentry )
return ( 1 );
/*
Make sure INT 2Fh is initialized. This is only
technically necessary to support DOS 2.x.
*/
int2Fvector = (unsigned long)GETVECT( 0x2F );
if ( 0UL == int2Fvector ) /* No INT 2Fh handler? */
return ( 0 ); /* then no IPX! */
ASM {
xor bx,bx /* clear return registers */
mov es,bx
mov di,bx
mov ax,7a00h /* FN 7A00: Detect IPX */
int 2fh
xor ah,ah
mov returnCode,ax /* save return code */
mov word ptr IPXentry,di /* store API entry */
mov word ptr IPXentry+2,es
mov word ptr IPXsignature,bx /* store signature */
mov word ptr IPXsignature+2,es
}
/*
Back up 4 bytes to point IPXsignature at the "IPX"
string.
If we can't do that, get the signature from the
location of INT 7Ah or INT 64h. In that case
we have to back up 6 bytes to point at "IPX".
*/
if ( FP_OFF( IPXsignature ) >= 4 )
IPXsignature = (char far *)IPXsignature - 4;
else {
IPXsignature = (char far *)GETVECT( 0x7A );
if ( NULL == IPXsignature )
IPXsignature = (char far *)GETVECT( 0x64 );
if ( NULL != IPXsignature )
IPXsignature = (char far *)IPXsignature - 6;
}
return ( 0xFF == returnCode ); /* AL = FF means success */
} /* DetectIPX() */
/*
GetIPXVersion obtains the address of the IPX entry point,
and returns the IPX version number from its
signature in RAM.
*/
int GetIPXVersion( void )
{
int verLow, verHigh;
static char sigPattern[ 4 ] = "IPX";
if ( !DetectIPX() )
return ( 0 );
/*
Compare the long int (4 bytes) at the signature with
if we can't find the signature, just return 3.00
*/
if ( *( (long far *)IPXsignature ) != *( (long *)sigPattern ) )
return ( 0x300 );
/* get the version bytes from memory */
verHigh = (int)*((unsigned char far *)IPXsignature + 4);
verLow = (int)*((unsigned char far *)IPXsignature + 5);
return ( ( verHigh << 8 ) | verLow );
} /* GetIPXVersion() */
/*
GetSPXVersion() uses the documented SPXInitialize function
to determine if SPX is present and return
its version number.
*/
int GetSPXVersion( void )
{
int returnCode, spxVer;
if ( !DetectIPX() )
return ( 0 );
ASM {
xor ax,ax /* must clear AL to avoid false positive! */
mov cx,ax
mov dx,ax
mov bx,0010h /* SPX Func #10h: SPX Initialize */
call IPXentry
xor ah,ah
mov returnCode,ax
mov spxVer,bx
}
if ( 0xFF != returnCode ) /* if he didn't say "yes" */
return ( 0 ); /* then no SPX present */
return ( spxVer ); /* else return the version */
} /* GetSPXVersion() */
/* eof: VERIPX.C */